package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.model.PsLine;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PsLineMapper extends BaseMapper<PsLine> {

    //  查询某个坐标在范围内最近的点
    @Select("SELECT fromsurvey,tosurveyno,ST_AsText(geom) as geom FROM ps_line_n WHERE ST_DWithin(geom, ST_MakePoint(#{X},#{Y}), #{distance}) ORDER BY ST_Distance(geom, ST_MakePoint(#{X},#{Y})) LIMIT 1;")
    List<PsLine> selectByPoint(@Param("X") Double coorX, @Param("Y") Double coorY, @Param("distance") Integer distance1);

    //    查询某个extent的数据
    @Select("SELECT fromsurvey,tosurveyno,ST_AsText(geom) as geom FROM ps_line_n WHERE ST_Intersects(geom, ST_MakeEnvelope(#{minX}, #{minY}, #{maxX}, #{maxY}));")
    List<PsLine> selectByExtend(@Param("minX") Double minX, @Param("minY") Double minY, @Param("maxX") Double maxX, @Param("maxY") Double maxy);


}
